#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include "array_aux.h"
void insertion_recursive_sort(vector<int>& array, int n)
{
  if(n ==1)
       return;
  insertion_recursive_sort(array, n-1);
  int key = array[n];
  int i = n-1;
  while (i > 0 && key < array[i])
  {
        array[i+1] = array[i];
        i --;
  }
  array[i+1] = key;

}
int binary_search(vector<int>& array, int begin, int end, int wanted)
{
    if( begin > end  )
    {
        return NULL;
    }
    int mid = (begin + end )/2;
    if (wanted == array[mid])
    {
       return mid;
    }
    else if (wanted > array[mid])
    {
       binary_search(array, mid+1, end, wanted);
    }
    else
    {
        binary_search(array, begin, mid-1, wanted);
    }
}

int main(int argc, char *argv[])
{

  vector<int>array = get_array(10);

  display_array(array);
  insertion_recursive_sort(array, 10);
  display_array(array);
  cout << binary_search(array, 1, 10, 333);
  system("PAUSE");
  return 0;
}
